#ifndef DISASM_H
#define DISASM_H

#include <stdint.h>
#include <stddef.h>
#include <stdio.h>
#include <sys/types.h>  // 添加pid_t定义

// 反汇编指令结构
typedef struct {
    uintptr_t address;      // 指令地址
    char mnemonic[32];      // 助记符
    char operands[128];     // 操作数
    char bytes[32];         // 原始字节
    size_t length;          // 指令长度
    char comment[256];      // 注释（如符号名）
} disasm_instruction_t;

// 反汇编结果结构
typedef struct {
    disasm_instruction_t *instructions;
    size_t count;
    size_t capacity;
} disasm_result_t;

// 反汇编器结构
typedef struct {
    pid_t pid;              // 目标进程ID
    uintptr_t base_address; // 反汇编基地址
    size_t max_instructions; // 最大指令数
} disasm_t;

// 函数声明
disasm_t* disasm_create(pid_t pid);
void disasm_destroy(disasm_t *disasm);
int disasm_disassemble(disasm_t *disasm, uintptr_t address, size_t count, disasm_result_t *result);
void disasm_result_destroy(disasm_result_t *result);
int disasm_print_instructions(disasm_t *disasm, uintptr_t address, size_t count);
int disasm_disassemble_function(disasm_t *disasm, const char *function_name, disasm_result_t *result);

// 指令格式化和显示函数
void disasm_format_instruction(const disasm_instruction_t *inst, char *buffer, size_t buffer_size);
void disasm_print_result(const disasm_result_t *result);

#endif // DISASM_H